package algorithm.leetcode;

public class Num83 {
    public static void main(String[] args) {
        ListNode head = new ListNode(1);
        ListNode head_1 = new ListNode(1);
        ListNode head_2 = new ListNode(2);
        ListNode head_3 = new ListNode(3);
        ListNode head_4 = new ListNode(3);
        head.next = head_1;
        head_1.next = head_2;
        head_2.next = head_3;
        head_3.next = head_4;
        System.out.println("before:" + head);
        ListNode listNode = deleteDuplicates(head);
        System.out.println("after:" + listNode);
    }

    public static ListNode deleteDuplicates(ListNode head) {
        if (head == null) return head;
        ListNode curr = head;
        while (curr.next != null) {
            if (curr.next.val == curr.val) {
                curr.next = curr.next.next;
            } else {
                curr = curr.next;
            }
        }
        return head;
    }

    static class ListNode {
        int val;
        ListNode next;

        ListNode() {
        }

        ListNode(int val) {
            this.val = val;
        }

        ListNode(int val, ListNode next) {
            this.val = val;
            this.next = next;
        }

        @Override
        public String toString() {
            return "ListNode{" +
                    "val=" + val +
                    ", next=" + next +
                    '}';
        }
    }
}
